package lily.phs.urh;

import lily.phs.object.HealthTest;
import lily.phs.object.HospitalHistory;
import lily.phs.object.SickbedHistory;
import lily.phs.urh.R;
import lily.ui.control.MyPopupWindow;


import android.content.Context;
import android.text.InputType;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;

/**
 * 健康体检表（Page 5）的界面布局和数据处理封装的view类
 * @author heckassitant
 *
 */
public class HealthTest_5 extends LinearLayout implements OnClickListener, OnFocusChangeListener{

	private MyPopupWindow mPopupWindow;
	private Context mContext;
	private int profileid = 0;
	private int testid = 0;
	
	private EditText et_cerebrovascul_other,et_kidney_other,et_heart_disease_other,et_vascular_disease_other,et_eye_disease_other,
	                 et_neur_disease,et_other_system_disease,et_hospital_admit_date_1,et_hospital_admit_date_2,et_hospital_leave_date_1,
	                 et_hospital_leave_date_2,et_hospital_reason_1,et_hospital_reason_2,et_hospital_1,et_hospital_2,et_hospital_number_1,
	                 et_hospital_number_2,et_sickbed_setup_date_1,et_sickbed_setup_date_2,et_sickbed_cancel_date_1,et_sickbed_cancel_date_2,
	                 et_sickbed_reason_1,et_sickbed_reason_2,et_sickbed_hospital_1,et_sickbed_hospital_2,et_sickbed_number_1,
	                 et_sickbed_number_2;
	
	private CheckBox cb_cerebrovascul_1,cb_cerebrovascul_2,cb_cerebrovascul_3,cb_cerebrovascul_4,cb_cerebrovascul_5,cb_cerebrovascul_6,
	                 cb_kidney_1,cb_kidney_2,cb_kidney_3,cb_kidney_4,cb_kidney_5,cb_kidney_6,cb_heart_disease_1,cb_heart_disease_2,
	                 cb_heart_disease_3,cb_heart_disease_4,cb_heart_disease_5,cb_heart_disease_6,cb_heart_disease_7,cb_vascular_disease_1,
	                 cb_vascular_disease_2,cb_vascular_disease_3,cb_vascular_disease_4,cb_eye_disease_1,cb_eye_disease_2,cb_eye_disease_3,
	                 cb_eye_disease_4,cb_eye_disease_5;
	private RadioGroup rgNeurDisease,rgOtherSystemDisease;
	private RadioButton rb_neur_disease_1,rb_neur_disease_2,rb_other_system_disease_1,rb_other_system_disease_2;
	
	private HealthTest ht;
	private HospitalHistory hh,hh1;
	private SickbedHistory sh,sh1;
	private View child;
	
	public HealthTest_5(Context context,int profileId,int testId) {
		super(context);
		// TODO Auto-generated constructor stub
		//档案编号
		this.profileid = profileId;
		this.testid = testId;
		this.mContext = context;
		
		final LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		child = inflater.inflate(R.layout.healthtest_5, null);
		
		//findViewsById();
		
		//initViews();
	}
	
	public int getProfileid() {
		return profileid;
	}

	public void setProfileid(int profileid) {
		this.profileid = profileid;
	}

	public int getTestid() {
		return testid;
	}

	public void setTestid(int testid) {
		this.testid = testid;
	}

	public  void findViewsById() {
		// TODO Auto-generated method stub
		
		et_cerebrovascul_other = (EditText)child.findViewById(R.id.ht5_cerebrovascul_other);
		et_cerebrovascul_other.setOnFocusChangeListener(this);
		et_cerebrovascul_other.setOnClickListener(this);
		et_kidney_other = (EditText)child.findViewById(R.id.ht5_kidney_other);
		et_kidney_other.setOnFocusChangeListener(this);
		et_kidney_other.setOnClickListener(this);
		et_heart_disease_other = (EditText)child.findViewById(R.id.ht5_heart_disease_other);
		et_heart_disease_other.setOnFocusChangeListener(this);
		et_heart_disease_other.setOnClickListener(this);
		et_vascular_disease_other = (EditText)child.findViewById(R.id.ht5_vascular_disease_other);
		et_vascular_disease_other.setOnFocusChangeListener(this);
		et_vascular_disease_other.setOnClickListener(this);
		et_eye_disease_other = (EditText)child.findViewById(R.id.ht5_eye_disease_other);
		et_eye_disease_other.setOnFocusChangeListener(this);
		et_eye_disease_other.setOnClickListener(this);
		et_neur_disease = (EditText)child.findViewById(R.id.ht5_neur_disease);
		et_neur_disease.setOnFocusChangeListener(this);
		et_neur_disease.setOnClickListener(this);
		et_other_system_disease = (EditText)child.findViewById(R.id.ht5_other_system_disease);
		et_other_system_disease.setOnFocusChangeListener(this);
		et_other_system_disease.setOnClickListener(this);
		et_hospital_admit_date_1 = (EditText)child.findViewById(R.id.ht5_hospital_admit_date_1);
        et_hospital_admit_date_1.setInputType(InputType.TYPE_NULL);//不显示虚拟键盘
        et_hospital_admit_date_1.setOnClickListener(this);
        et_hospital_admit_date_1.setOnFocusChangeListener(this);
        
        
        et_hospital_admit_date_2 = (EditText)child.findViewById(R.id.ht5_hospital_admit_date_2);
        et_hospital_admit_date_2.setInputType(InputType.TYPE_NULL);//不显示虚拟键盘
        et_hospital_admit_date_2.setOnClickListener(this);
        et_hospital_admit_date_2.setOnFocusChangeListener(this);
        
        
        et_hospital_leave_date_1 = (EditText)child.findViewById(R.id.ht5_hospital_leave_date_1);
        et_hospital_leave_date_1.setInputType(InputType.TYPE_NULL);//不显示虚拟键盘
        et_hospital_leave_date_1.setOnClickListener(this);
        et_hospital_leave_date_1.setOnFocusChangeListener(this);
        
        
        et_hospital_leave_date_2 = (EditText)child.findViewById(R.id.ht5_hospital_leave_date_2);
        et_hospital_leave_date_2.setInputType(InputType.TYPE_NULL);//不显示虚拟键盘
        et_hospital_leave_date_2.setOnClickListener(this);
        et_hospital_leave_date_2.setOnFocusChangeListener(this);
        
        

        et_hospital_reason_1 = (EditText)child.findViewById(R.id.ht5_hospital_reason_1);
        et_hospital_reason_2 = (EditText)child.findViewById(R.id.ht5_hospital_reason_2);
        et_hospital_1 = (EditText)child.findViewById(R.id.ht5_hospital_1);
        et_hospital_2 = (EditText)child.findViewById(R.id.ht5_hospital_2);
        et_hospital_number_1 = (EditText)child.findViewById(R.id.ht5_hospital_number_1);
        et_hospital_number_2 = (EditText)child.findViewById(R.id.ht5_hospital_number_2);
        et_sickbed_setup_date_1 = (EditText)child.findViewById(R.id.ht5_sickbed_setup_date_1);
        et_sickbed_setup_date_1.setInputType(InputType.TYPE_NULL);//不显示虚拟键盘
        et_sickbed_setup_date_1.setOnClickListener(this);
        et_sickbed_setup_date_1.setOnFocusChangeListener(this);
        et_sickbed_setup_date_2 = (EditText)child.findViewById(R.id.ht5_sickbed_setup_date_2);
        et_sickbed_setup_date_2.setInputType(InputType.TYPE_NULL);//不显示虚拟键盘
        et_sickbed_setup_date_2.setOnClickListener(this);
        et_sickbed_setup_date_2.setOnFocusChangeListener(this);
        et_sickbed_cancel_date_1 = (EditText)child.findViewById(R.id.ht5_sickbed_cancel_date_1);
        et_sickbed_cancel_date_1.setInputType(InputType.TYPE_NULL);//不显示虚拟键盘
        et_sickbed_cancel_date_1.setOnClickListener(this);
        et_sickbed_cancel_date_1.setOnFocusChangeListener(this);
        et_sickbed_cancel_date_2 = (EditText)child.findViewById(R.id.ht5_sickbed_cancel_date_2);
        et_sickbed_cancel_date_2.setInputType(InputType.TYPE_NULL);//不显示虚拟键盘
        et_sickbed_cancel_date_2.setOnClickListener(this);
        et_sickbed_cancel_date_2.setOnFocusChangeListener(this);
        et_sickbed_reason_1 = (EditText)child.findViewById(R.id.ht5_sickbed_reason_1);
        et_sickbed_reason_2 = (EditText)child.findViewById(R.id.ht5_sickbed_reason_2);
        et_sickbed_hospital_1 = (EditText)child.findViewById(R.id.ht5_sickbed_hospital_1);
        et_sickbed_hospital_2 = (EditText)child.findViewById(R.id.ht5_sickbed_hospital_2);
        et_sickbed_number_1 = (EditText)child.findViewById(R.id.ht5_sickbed_number_1);
        et_sickbed_number_2 = (EditText)child.findViewById(R.id.ht5_sickbed_number_2);
		cb_cerebrovascul_1 = (CheckBox)child.findViewById(R.id.ht5_cerebrovascul_1);
		cb_cerebrovascul_2 = (CheckBox)child.findViewById(R.id.ht5_cerebrovascul_2);
		cb_cerebrovascul_3 = (CheckBox)child.findViewById(R.id.ht5_cerebrovascul_3);
		cb_cerebrovascul_4 = (CheckBox)child.findViewById(R.id.ht5_cerebrovascul_4);
		cb_cerebrovascul_5 = (CheckBox)child.findViewById(R.id.ht5_cerebrovascul_5);
		cb_cerebrovascul_6 = (CheckBox)child.findViewById(R.id.ht5_cerebrovascul_6);
        cb_kidney_1 = (CheckBox)child.findViewById(R.id.ht5_kidney_1);
        cb_kidney_2 = (CheckBox)child.findViewById(R.id.ht5_kidney_2);
        cb_kidney_3 = (CheckBox)child.findViewById(R.id.ht5_kidney_3);
        cb_kidney_4 = (CheckBox)child.findViewById(R.id.ht5_kidney_4);
        cb_kidney_5 = (CheckBox)child.findViewById(R.id.ht5_kidney_5);
        cb_kidney_6 = (CheckBox)child.findViewById(R.id.ht5_kidney_6);
        cb_heart_disease_1 = (CheckBox)child.findViewById(R.id.ht5_heart_disease_1);
        cb_heart_disease_2 = (CheckBox)child.findViewById(R.id.ht5_heart_disease_2);
        cb_heart_disease_3 = (CheckBox)child.findViewById(R.id.ht5_heart_disease_3);
        cb_heart_disease_4 = (CheckBox)child.findViewById(R.id.ht5_heart_disease_4);
        cb_heart_disease_5 = (CheckBox)child.findViewById(R.id.ht5_heart_disease_5);
        cb_heart_disease_6 = (CheckBox)child.findViewById(R.id.ht5_heart_disease_6);
        cb_heart_disease_7 = (CheckBox)child.findViewById(R.id.ht5_heart_disease_7);
        cb_vascular_disease_1 = (CheckBox)child.findViewById(R.id.ht5_vascular_disease_1);
        cb_vascular_disease_2 = (CheckBox)child.findViewById(R.id.ht5_vascular_disease_2);
        cb_vascular_disease_3 = (CheckBox)child.findViewById(R.id.ht5_vascular_disease_3);
        cb_vascular_disease_4 = (CheckBox)child.findViewById(R.id.ht5_vascular_disease_4);
        cb_eye_disease_1 = (CheckBox)child.findViewById(R.id.ht5_eye_disease_1);
        cb_eye_disease_2 = (CheckBox)child.findViewById(R.id.ht5_eye_disease_2);
        cb_eye_disease_3 = (CheckBox)child.findViewById(R.id.ht5_eye_disease_3);
        cb_eye_disease_4 = (CheckBox)child.findViewById(R.id.ht5_eye_disease_4);
        cb_eye_disease_5 = (CheckBox)child.findViewById(R.id.ht5_eye_disease_5);
		rb_neur_disease_1 = (RadioButton)child.findViewById(R.id.ht5_neur_disease_1);
		rb_neur_disease_2 = (RadioButton)child.findViewById(R.id.ht5_neur_disease_2);
		rb_other_system_disease_1 = (RadioButton)child.findViewById(R.id.ht5_other_system_disease_1);
		rb_other_system_disease_2 = (RadioButton)child.findViewById(R.id.ht5_other_system_disease_2);
		rgNeurDisease = (RadioGroup)child.findViewById(R.id.radioGroup8);
		rgOtherSystemDisease = (RadioGroup)child.findViewById(R.id.radioGroup1);
	}
	
	/**
	 * 添加view到contentview
	 */
	public void setMyView(){
		this.removeAllViews();
		LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
		this.addView(child,lp);
		
	}
	
	/**
	 * 将整个界面作为一个view对象
	 * @return 整个界面view
	 */
	public View getMyView(){
		return this.child;
	}
	
	/**
	 * 检出数据
	 */
	public void fetchData(){
		ht = new HealthTest(mContext);
	    ht.selectHealthTest(this.profileid,this.testid);
	
	    hh = new HospitalHistory(mContext);
	    hh.selectHospitalHistory(this.profileid,this.testid,1);
	
	    hh1 = new HospitalHistory(mContext);
	    hh1.selectHospitalHistory(this.profileid,this.testid,2);
	
	    sh = new SickbedHistory(mContext);
	    sh.selectSickbedHistory(this.profileid, this.testid, 1);
	
	    sh1 = new SickbedHistory(mContext);
	    sh1.selectSickbedHistory(this.profileid, this.testid, 2);
	
	}
	/**
	 * 根据ID从数据库中读出数据并填充views
	 */
	public void initViews() {
		// TODO Auto-generated method stub
		
		initialState();
		
		String temp = "";
		int itemp = -1;
//		float ftemp = 0.0f;
		
		temp = ht.getHete_cerebrovascul();
		if(temp.length()>0){
			String[] ss = temp.split(",");
			for(int i=0;i<ss.length;i++){
				int k = Integer.parseInt(ss[i]);
				switch(k){
				case 1:
					cb_cerebrovascul_1.setChecked(true);
					break;
				case 2:
					cb_cerebrovascul_2.setChecked(true);
					break;
				case 3:
					cb_cerebrovascul_3.setChecked(true);
					break;
				case 4:
					cb_cerebrovascul_4.setChecked(true);
					break;
				case 5:
					cb_cerebrovascul_5.setChecked(true);
					break;
				case 6:{
					cb_cerebrovascul_6.setChecked(true);
					temp = ht.getHete_cerebrovascul_other();
					et_cerebrovascul_other.setText(temp);
					break;
				}
				}
			}
		}
		
		temp = ht.getHete_kidney_disease();
		if(temp.length()>0){
			String[] ss = temp.split(",");
			for(int i=0;i<ss.length;i++){
				int k = Integer.parseInt(ss[i]);
				switch(k){
				case 1:
					cb_kidney_1.setChecked(true);
					break;
				case 2:
					cb_kidney_2.setChecked(true);
					break;
				case 3:
					cb_kidney_3.setChecked(true);
					break;
				case 4:
					cb_kidney_4.setChecked(true);
					break;
				case 5:
					cb_kidney_5.setChecked(true);
					break;
				case 6:{
					cb_kidney_6.setChecked(true);
					temp = ht.getHete_kidney_disease_other();
					et_kidney_other.setText(temp);
					break;
				}
				}
			}
		}
		
		temp = ht.getHete_heart_disease();
		if(temp.length()>0){
			String[] ss = temp.split(",");
			for(int i=0;i<ss.length;i++){
				int k = Integer.parseInt(ss[i]);
				switch(k){
				case 1:
					cb_heart_disease_1.setChecked(true);
					break;
				case 2:
					cb_heart_disease_2.setChecked(true);
					break;
				case 3:
					cb_heart_disease_3.setChecked(true);
					break;
				case 4:
					cb_heart_disease_4.setChecked(true);
					break;
				case 5:
					cb_heart_disease_5.setChecked(true);
					break;
				case 6:
					cb_heart_disease_6.setChecked(true);
					break;
				case 7:{
					cb_heart_disease_7.setChecked(true);
					temp = ht.getHete_heart_disease_other();
					et_heart_disease_other.setText(temp);
					break;
				}
				}
			}
		}
		
		temp = ht.getHete_vascular_disease();
		if(temp.length()>0){
			String[] ss = temp.split(",");
			for(int i=0;i<ss.length;i++){
				int k = Integer.parseInt(ss[i]);
				switch(k){
				case 1:
					cb_vascular_disease_1.setChecked(true);
					break;
				case 2:
					cb_vascular_disease_2.setChecked(true);
					break;
				case 3:
					cb_vascular_disease_3.setChecked(true);
					break;
				case 4:{
					cb_vascular_disease_4.setChecked(true);
					temp = ht.getHete_vascular_disease_other();
					et_vascular_disease_other.setText(temp);
					break;
				}
				}
			}
		}
		
		temp = ht.getHete_eye_disease();
		if(temp.length()>0){
			String[] ss = temp.split(",");
			for(int i=0;i<ss.length;i++){
				int k = Integer.parseInt(ss[i]);
				switch(k){
				case 1:
					cb_eye_disease_1.setChecked(true);
					break;
				case 2:
					cb_eye_disease_2.setChecked(true);
					break;
				case 3:
					cb_eye_disease_3.setChecked(true);
					break;
				case 4:
					cb_eye_disease_4.setChecked(true);
					break;
				case 5:{
					cb_eye_disease_5.setChecked(true);
					temp = ht.getHete_eye_disease_other();
					et_eye_disease_other.setText(temp);
					break;
				}
				}
			}
		}
		
		itemp = ht.getHete_has_neur_disease();
		switch(itemp){
		case 1:
			rgNeurDisease.check(0);
			rb_neur_disease_1.setChecked(true);
			break;
		case 2:{
			rgNeurDisease.check(1);
			rb_neur_disease_2.setChecked(true);
			temp = ht.getHete_neur_disease();
			et_neur_disease.setText(temp);
		}
		}
		
		itemp = ht.getHete_has_other_system_disease();
		switch(itemp){
		case 1:
			rgOtherSystemDisease.check(0);
			rb_other_system_disease_1.setChecked(true);
			break;
		case 2:{
			rgOtherSystemDisease.check(1);
			rb_other_system_disease_2.setChecked(true);
			temp = ht.getHete_other_system_disease();
			et_other_system_disease.setText(temp);
		}
		}
		
		//住院史表---2项
		//HospitalHistory hh = new HospitalHistory(mContext);
		//hh.selectHospitalHistory(this.profileid,this.testid,1);
		temp = hh.getHohi_admit_date();
		et_hospital_admit_date_1.setText(temp);
		temp = hh.getHohi_leave_date();
		et_hospital_leave_date_1.setText(temp);
		temp = hh.getHohi_reason();
		et_hospital_reason_1.setText(temp);
		temp = hh.getHohi_hospital();
		et_hospital_1.setText(temp);
		temp = hh.getHohi_number();
		et_hospital_number_1.setText(temp);
		
		//HospitalHistory hh1 = new HospitalHistory(mContext);
		//hh1.selectHospitalHistory(this.profileid,this.testid,2);
		temp = hh1.getHohi_admit_date();
		et_hospital_admit_date_2.setText(temp);
		temp = hh1.getHohi_leave_date();
		et_hospital_leave_date_2.setText(temp);
		temp = hh1.getHohi_reason();
		et_hospital_reason_2.setText(temp);
		temp = hh1.getHohi_hospital();
		et_hospital_2.setText(temp);
		temp = hh1.getHohi_number();
		et_hospital_number_2.setText(temp);		
		
		//病床史---2项
		//SickbedHistory sh = new SickbedHistory(mContext);
		//sh.selectSickbedHistory(this.profileid, this.testid, 1);
		temp = sh.getSihi_setup_date();
		et_sickbed_setup_date_1.setText(temp);
		temp = sh.getSihi_cancel_date();
		et_sickbed_cancel_date_1.setText(temp);
		temp = sh.getSihi_reason();
		et_sickbed_reason_1.setText(temp);
		temp = sh.getSihi_hospital();
		et_sickbed_hospital_1.setText(temp);
		temp = sh.getSihi_number();
		et_sickbed_number_1.setText(temp);
		
		//sh.selectSickbedHistory(this.profileid, this.testid, 2);
		temp = sh1.getSihi_setup_date();
		et_sickbed_setup_date_2.setText(temp);
		temp = sh1.getSihi_cancel_date();
		et_sickbed_cancel_date_2.setText(temp);
		temp = sh1.getSihi_reason();
		et_sickbed_reason_2.setText(temp);
		temp = sh1.getSihi_hospital();
		et_sickbed_hospital_2.setText(temp);
		temp = sh1.getSihi_number();
		et_sickbed_number_2.setText(temp);
		
	}
	
	/**
	 * 初始时为空表：横线为空，所有选择项未选中
	 */
	private void initialState() {
		// TODO Auto-generated method stub
		et_cerebrovascul_other.setText("");
		et_kidney_other.setText("");
		et_heart_disease_other.setText("");
		et_vascular_disease_other.setText("");
		et_eye_disease_other.setText("");
        et_neur_disease.setText("");
        et_other_system_disease.setText("");
        et_hospital_admit_date_1.setText("");
        et_hospital_admit_date_2.setText("");
        et_hospital_leave_date_1.setText("");
        et_hospital_leave_date_2.setText("");
        et_hospital_reason_1.setText("");
        et_hospital_reason_2.setText("");
        et_hospital_1.setText("");
        et_hospital_2.setText("");
        et_hospital_number_1.setText("");
        et_hospital_number_2.setText("");
        et_sickbed_setup_date_1.setText("");
        et_sickbed_setup_date_2.setText("");
        et_sickbed_cancel_date_1.setText("");
        et_sickbed_cancel_date_2.setText("");
        et_sickbed_reason_1.setText("");
        et_sickbed_reason_2.setText("");
        et_sickbed_hospital_1.setText("");
        et_sickbed_hospital_2.setText("");
        et_sickbed_number_1.setText("");
        et_sickbed_number_2.setText("");
		cb_cerebrovascul_1.setChecked(false);
		cb_cerebrovascul_2.setChecked(false);
		cb_cerebrovascul_3.setChecked(false);
		cb_cerebrovascul_4.setChecked(false);
		cb_cerebrovascul_5.setChecked(false);
		cb_cerebrovascul_6.setChecked(false);
        cb_kidney_1.setChecked(false);
        cb_kidney_2.setChecked(false);
        cb_kidney_3.setChecked(false);
        cb_kidney_4.setChecked(false);
        cb_kidney_5.setChecked(false);
        cb_kidney_6.setChecked(false);
        cb_heart_disease_1.setChecked(false);
        cb_heart_disease_2.setChecked(false);
        cb_heart_disease_3.setChecked(false);
        cb_heart_disease_4.setChecked(false);
        cb_heart_disease_5.setChecked(false);
        cb_heart_disease_6.setChecked(false);
        cb_heart_disease_7.setChecked(false);
        cb_vascular_disease_1.setChecked(false);
        cb_vascular_disease_2.setChecked(false);
        cb_vascular_disease_3.setChecked(false);
        cb_vascular_disease_4.setChecked(false);
        cb_eye_disease_1.setChecked(false);
        cb_eye_disease_2.setChecked(false);
        cb_eye_disease_3.setChecked(false);
        cb_eye_disease_4.setChecked(false);
        cb_eye_disease_5.setChecked(false);
		rb_neur_disease_1.setChecked(false);
		rb_neur_disease_2.setChecked(false);
		rb_other_system_disease_1.setChecked(false);
		rb_other_system_disease_2.setChecked(false);
	}

	/**
	 * 读取views的值并保存至ID对应的记录中
	 */
	public void saveViews() {
		HealthTest ht = new HealthTest(mContext);
		ht.selectHealthTest(profileid, testid);
		String temp = "";
		StringBuffer sb;
//		int itemp = -1;
		
		sb = new StringBuffer();
		if(cb_cerebrovascul_1.isChecked()==true){
			sb.append("1,");
		}
		if(cb_cerebrovascul_2.isChecked()==true){
			sb.append("2,");
		}
		if(cb_cerebrovascul_3.isChecked()==true){
			sb.append("3,");
		}
		if(cb_cerebrovascul_4.isChecked()==true){
			sb.append("4,");
		}
		if(cb_cerebrovascul_5.isChecked()==true){
			sb.append("5,");
		}
		if(cb_cerebrovascul_6.isChecked()==true){
			sb.append("6,");
			temp = et_cerebrovascul_other.getText().toString();
			ht.setHete_cerebrovascul_other(temp);
		}
		ht.setHete_cerebrovascul(sb.toString());
		
		sb = new StringBuffer();
		if(cb_kidney_1.isChecked()==true){
			sb.append("1,");
		}
		if(cb_kidney_2.isChecked()==true){
			sb.append("2,");
		}
		if(cb_kidney_3.isChecked()==true){
			sb.append("3,");
		}
		if(cb_kidney_4.isChecked()==true){
			sb.append("4,");
		}
		if(cb_kidney_5.isChecked()==true){
			sb.append("5,");
		}
		if(cb_kidney_6.isChecked()==true){
			sb.append("6,");
			temp = et_kidney_other.getText().toString();
			ht.setHete_kidney_disease_other(temp);
		}
		ht.setHete_kidney_disease(sb.toString());
		
		sb = new StringBuffer();
		if(cb_heart_disease_1.isChecked()==true){
			sb.append("1,");
		}
		if(cb_heart_disease_2.isChecked()==true){
			sb.append("2,");
		}
		if(cb_heart_disease_3.isChecked()==true){
			sb.append("3,");
		}
		if(cb_heart_disease_4.isChecked()==true){
			sb.append("4,");
		}
		if(cb_heart_disease_5.isChecked()==true){
			sb.append("5,");
		}
		if(cb_heart_disease_6.isChecked()==true){
			sb.append("6,");
		}
		if(cb_heart_disease_7.isChecked()==true){
			sb.append("7,");
			temp = et_heart_disease_other.getText().toString();
			ht.setHete_heart_disease_other(temp);
		}
		ht.setHete_heart_disease(sb.toString());
		
		sb = new StringBuffer();
		if(cb_vascular_disease_1.isChecked()==true){
			sb.append("1,");
		}
		if(cb_vascular_disease_2.isChecked()==true){
			sb.append("2,");
		}
		if(cb_vascular_disease_3.isChecked()==true){
			sb.append("3,");
		}
		if(cb_vascular_disease_4.isChecked()==true){
			sb.append("4,");
			temp = et_vascular_disease_other.getText().toString();
			ht.setHete_vascular_disease_other(temp);
		}
		ht.setHete_vascular_disease(sb.toString());
		
		sb = new StringBuffer();
		if(cb_eye_disease_1.isChecked()==true){
			sb.append("1,");
		}
		if(cb_eye_disease_2.isChecked()==true){
			sb.append("2,");
		}
		if(cb_eye_disease_3.isChecked()==true){
			sb.append("3,");
		}
		if(cb_eye_disease_4.isChecked()==true){
			sb.append("4,");
		}
		if(cb_eye_disease_5.isChecked()==true){
			sb.append("5,");
			temp = et_eye_disease_other.getText().toString();
			ht.setHete_eye_disease_other(temp);
		}
		ht.setHete_eye_disease(sb.toString());
		
		if(rb_neur_disease_1.isChecked()==true){
			ht.setHete_has_neur_disease(1);
		}else if(rb_neur_disease_2.isChecked()==true){
			ht.setHete_has_neur_disease(2);
			temp = et_neur_disease.getText().toString();
			ht.setHete_neur_disease(temp);
		}
		
		if(rb_other_system_disease_1.isChecked()==true){
			ht.setHete_has_other_system_disease(1);
		}else if(rb_other_system_disease_2.isChecked()==true){
			ht.setHete_has_other_system_disease(2);
			temp = et_other_system_disease.getText().toString();
			ht.setHete_other_system_disease(temp);
		}
		
		ht.updateHealthTest(this.profileid, this.testid);
		
		//住院史信息
		HospitalHistory hh = new HospitalHistory(mContext);
		hh.setHohi_profileid(profileid);
		hh.setHohi_testid(testid);
		
		hh.setHohi_id(1);
		temp = et_hospital_admit_date_1.getText().toString();
		hh.setHohi_admit_date(temp);
		temp = et_hospital_leave_date_1.getText().toString();
		hh.setHohi_leave_date(temp);
		temp = et_hospital_reason_1.getText().toString();
		hh.setHohi_reason(temp);
		temp = et_hospital_1.getText().toString();
		hh.setHohi_hospital(temp);
		temp = et_hospital_number_1.getText().toString();
		hh.setHohi_number(temp);
		hh.updateHospitalHistory(profileid, testid, 1);
		
		hh.setHohi_id(2);
		temp = et_hospital_admit_date_2.getText().toString();
		hh.setHohi_admit_date(temp);
		temp = et_hospital_leave_date_2.getText().toString();
		hh.setHohi_leave_date(temp);
		temp = et_hospital_reason_2.getText().toString();
		hh.setHohi_reason(temp);
		temp = et_hospital_2.getText().toString();
		hh.setHohi_hospital(temp);
		temp = et_hospital_number_2.getText().toString();
		hh.setHohi_number(temp);
		hh.updateHospitalHistory(profileid, testid, 2);
		
		//病床史信息
		SickbedHistory sh = new SickbedHistory(mContext);
		sh.setSihi_profileid(profileid);
		sh.setSihi_testid(testid);
		
		sh.setSihi_id(1);
		temp = et_sickbed_setup_date_1.getText().toString();
		sh.setSihi_setup_date(temp);
		temp = et_sickbed_cancel_date_1.getText().toString();
		sh.setSihi_cancel_date(temp);
		temp = et_sickbed_reason_1.getText().toString();
		sh.setSihi_reason(temp);
		temp = et_sickbed_hospital_1.getText().toString();
		sh.setSihi_hospital(temp);
		temp = et_sickbed_number_1.getText().toString();
		sh.setSihi_number(temp);
		sh.updateSickbedHistory(profileid, testid, 1);
		
		
		sh.setSihi_id(2);
		temp = et_sickbed_setup_date_2.getText().toString();
		sh.setSihi_setup_date(temp);
		temp = et_sickbed_cancel_date_2.getText().toString();
		sh.setSihi_cancel_date(temp);
		temp = et_sickbed_reason_2.getText().toString();
		sh.setSihi_reason(temp);
		temp = et_sickbed_hospital_2.getText().toString();
		sh.setSihi_hospital(temp);
		temp = et_sickbed_number_2.getText().toString();
		sh.setSihi_number(temp);
		sh.updateSickbedHistory(profileid, testid, 2);
	}


	
	
	
	
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(v==et_hospital_admit_date_1){
			mPopupWindow = new MyPopupWindow(mContext);			
			mPopupWindow.showAtLocation(v.findViewById(R.id.ht5_hospital_admit_date_1), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_hospital_admit_date_1.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_hospital_admit_date_2){
			mPopupWindow = new MyPopupWindow(mContext);			
			mPopupWindow.showAtLocation(v.findViewById(R.id.ht5_hospital_admit_date_2), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_hospital_admit_date_2.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_hospital_leave_date_1){
			mPopupWindow = new MyPopupWindow(mContext);			
			mPopupWindow.showAtLocation(v.findViewById(R.id.ht5_hospital_leave_date_1), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_hospital_leave_date_1.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_hospital_leave_date_2){
			mPopupWindow = new MyPopupWindow(mContext);			
			mPopupWindow.showAtLocation(v.findViewById(R.id.ht5_hospital_leave_date_2), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_hospital_leave_date_2.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_sickbed_setup_date_1){
			mPopupWindow = new MyPopupWindow(mContext);			
			mPopupWindow.showAtLocation(v.findViewById(R.id.ht5_sickbed_setup_date_1), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_sickbed_setup_date_1.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_sickbed_setup_date_2){
			mPopupWindow = new MyPopupWindow(mContext);			
			mPopupWindow.showAtLocation(v.findViewById(R.id.ht5_sickbed_setup_date_2), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_sickbed_setup_date_2.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_sickbed_cancel_date_1){
			mPopupWindow = new MyPopupWindow(mContext);			
			mPopupWindow.showAtLocation(v.findViewById(R.id.ht5_sickbed_cancel_date_1), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_sickbed_cancel_date_1.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_sickbed_cancel_date_2){
			mPopupWindow = new MyPopupWindow(mContext);			
			mPopupWindow.showAtLocation(v.findViewById(R.id.ht5_sickbed_cancel_date_2), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_sickbed_cancel_date_2.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_cerebrovascul_other){
			cb_cerebrovascul_6.setChecked(true);
		}
		else if(v==et_kidney_other){
			cb_kidney_6.setChecked(true);
		}
		else if(v==et_heart_disease_other){
			cb_heart_disease_7.setChecked(true);
		}
		else if(v==et_vascular_disease_other){
			cb_vascular_disease_4.setChecked(true);
		}
		else if(v==et_eye_disease_other){
			cb_eye_disease_5.setChecked(true);
		}
		else if(v==et_neur_disease){
			rb_neur_disease_1.setChecked(false);
			rb_neur_disease_2.setChecked(true);
		}
		else if(v==et_other_system_disease){
			rb_other_system_disease_1.setChecked(false);
			rb_other_system_disease_2.setChecked(true);
		}
		
	}

	@Override
	public void onFocusChange(View v, boolean hasFocus) {
		// TODO Auto-generated method stub
		if(hasFocus){
			if(v==et_cerebrovascul_other){
				cb_cerebrovascul_6.setChecked(true);
			}
			else if(v==et_kidney_other){
				cb_kidney_6.setChecked(true);
			}
			else if(v==et_heart_disease_other){
				cb_heart_disease_7.setChecked(true);
			}
			else if(v==et_vascular_disease_other){
				cb_vascular_disease_4.setChecked(true);
			}
			else if(v==et_eye_disease_other){
				cb_eye_disease_5.setChecked(true);
			}
			else if(v==et_neur_disease){
				rb_neur_disease_1.setChecked(false);
				rb_neur_disease_2.setChecked(true);
			}
			else if(v==et_other_system_disease){
				rb_other_system_disease_1.setChecked(false);
				rb_other_system_disease_2.setChecked(true);
			}
		}
		if(v==et_hospital_admit_date_1&&hasFocus){
			mPopupWindow = new MyPopupWindow(getContext());			
			mPopupWindow.showAtLocation(findViewById(R.id.ht5_hospital_admit_date_1), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_hospital_admit_date_1.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_hospital_admit_date_2&&hasFocus){
			mPopupWindow = new MyPopupWindow(getContext());			
			mPopupWindow.showAtLocation(findViewById(R.id.ht5_hospital_admit_date_2), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_hospital_admit_date_2.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_hospital_leave_date_1&&hasFocus){
			mPopupWindow = new MyPopupWindow(getContext());			
			mPopupWindow.showAtLocation(findViewById(R.id.ht5_hospital_leave_date_1), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_hospital_leave_date_1.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_hospital_leave_date_2&&hasFocus){
			mPopupWindow = new MyPopupWindow(getContext());			
			mPopupWindow.showAtLocation(findViewById(R.id.ht5_hospital_leave_date_2), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_hospital_leave_date_2.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_sickbed_setup_date_1&&hasFocus){
			mPopupWindow = new MyPopupWindow(getContext());			
			mPopupWindow.showAtLocation(findViewById(R.id.ht5_sickbed_setup_date_1), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_sickbed_setup_date_1.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_sickbed_setup_date_2&&hasFocus){
			mPopupWindow = new MyPopupWindow(getContext());			
			mPopupWindow.showAtLocation(findViewById(R.id.ht5_sickbed_setup_date_2), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_sickbed_setup_date_2.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_sickbed_cancel_date_1&&hasFocus){
			mPopupWindow = new MyPopupWindow(getContext());			
			mPopupWindow.showAtLocation(findViewById(R.id.ht5_sickbed_cancel_date_1), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_sickbed_cancel_date_1.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
		else if(v==et_sickbed_cancel_date_2&&hasFocus){
			mPopupWindow = new MyPopupWindow(getContext());			
			mPopupWindow.showAtLocation(findViewById(R.id.ht5_sickbed_cancel_date_2), Gravity.CENTER, 0, 0);

			Button btn=mPopupWindow.getButton();
			btn.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					et_sickbed_cancel_date_2.setText(mPopupWindow.getDate());
					mPopupWindow.dismiss();
				}
				
			});
		}
	}
	

}
